package cn.edu.zafu.bigdata.x.wgj.e;

public class Cube implements Comparable<Cube> {
    private double length;
    private double width;
    private double height;
    //构造方法
    public Cube(double length,double width,double height){
        this.length=length;
        this.width=width;
        this.height=height;
    }
    //获取方法
    public double getLength(){
        return length;
    }
    public double getWidth(){
        return width;
    }
    public double getHeight(){
        return height;
    }
    //重写equals方法
    @Override
    public boolean equals(Object obj){
        if(this==obj){
            return true;
        }
        if(obj==null||getClass()!=obj.getClass()){
            return false;
        }
        Cube other=(Cube) obj;
        return Double.compare(length,other.length)==0 &&
                Double.compare(width,other.width)==0 &&
                Double.compare(height,other.height)==0;
    }
    public static void main(String[] args){
        Cube cube1=new Cube(5.0,5.0,5.0);
        Cube cube2=new Cube(5.0,5.0,5.0);
        Cube cube3=new Cube(3.0,3.0,3.0);
        System.out.println("cube1和cube2是否相等:"+cube1.equals(cube2));
        System.out.println("cube1和cube3是否相等:"+cube1.equals(cube3));
    }

    @Override
    public int compareTo(Cube o) {
        if(this.length*this.width*this.height<o.length*o.width*o.height){
            return -1;
        } else if (this.length*this.width*this.height>o.length*o.width*o.height) {
            return 1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "Length:"+length+",Width:"+width+",Height:"+height;
    }
}
